<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <input type="text" />
    <button class="set">存储数据</button>
    <button class="get">获取数据</button>
    <button class="remove">删除数据</button>
    <button class="del">清空所有数据</button>

    <script>
      let input_text = document.querySelector("input");
      let button_set = document.querySelector(".set");
      let button_get = document.querySelector(".get");
      let button_remove = document.querySelector(".remove");
      let button_del = document.querySelector(".del");

      button_set.addEventListener("click", function () {
        let text = input_text.value;
        sessionStorage.setItem("name", text);
      });

      button_get.addEventListener("click", function () {
        console.log(sessionStorage.getItem("name"));
      });

      button_remove.addEventListener("click", function () {
        sessionStorage.removeItem("name");
      });

      button_del.addEventListener("click", function () {
        sessionStorage.clear();
      });
    </script>
  </body>
</html>
